2020-2021 Sunseeker Telemetry and Lighting System
adc10_a_ex6_refToggle.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 
34 //******************************************************************************
71 //******************************************************************************
72 
73 //Software delay function definition
74 void delay (void);
75 
76 void main (void)
77 {
78  uint8_t vRefStatus;
79 
80  //Stop Watchdog Timer
81  WDT_A_hold(WDT_A_BASE);
82 
83  //Initialize the ADC10_A Module
84  /*
85  * Base Address for the ADC10_A Module
86  * Use internal ADC10_A bit as sample/hold signal to start conversion
87  * USE MODOSC 5MHZ Digital Oscillator as clock source
88  * Use default clock divider of 1
89  */
90  ADC10_A_init(ADC10_A_BASE,
91  ADC10_A_SAMPLEHOLDSOURCE_SC,
92  ADC10_A_CLOCKSOURCE_ADC10OSC,
93  ADC10_A_CLOCKDIVIDER_1);
94 
95  ADC10_A_enable(ADC10_A_BASE);
96 
97  /*
98  * Base Address for the ADC10_A Module
99  * Sample/hold for 16 clock cycles
100  * Do not enable Multiple Sampling
101  */
102  ADC10_A_setupSamplingTimer(ADC10_A_BASE,
103  ADC10_A_CYCLEHOLD_16_CYCLES,
104  ADC10_A_MULTIPLESAMPLESDISABLE);
105 
106  //Configure Memory Buffer
107  /*
108  * Base Address for the ADC10_A Module
109  * Use input A1
110  * Use positive reference of Internally generated Vref
111  * Use negative reference of AVss
112  */
113  ADC10_A_configureMemory(ADC10_A_BASE,
114  ADC10_A_INPUT_A1,
115  ADC10_A_VREFPOS_INT,
116  ADC10_A_VREFNEG_AVSS);
117 
118  //Configure internal reference
119  //If ref generator busy, WAIT
120  while ( REF_BUSY == Ref_isRefGenBusy(REF_BASE) ) ;
121  //Select internal ref = 1.5V
122  Ref_setReferenceVoltage(REF_BASE,
123  REF_VREF1_5V);
124  //Internal Reference ON
125  Ref_enableReferenceVoltage(REF_BASE);
126  //vRefStatus == 1 for Vref == 1.5V
127  vRefStatus = 1;
128 
129  //Delay (~75us) for Ref to settle
130  __delay_cycles(75);
131 
132  //Set P1.0 to output direction
133  GPIO_setAsOutputPin(GPIO_PORT_P1,
134  GPIO_PIN0
135  );
136 
137  //Clear P1.0 LED off
138  GPIO_setOutputLowOnPin(GPIO_PORT_P1,
139  GPIO_PIN0
140  );
141 
142  while (1)
143  {
144  //Enable and Start the conversion
145  //in Single-Channel, Single-Conversion Mode
146  ADC10_A_startConversion(ADC10_A_BASE,
147  ADC10_A_SINGLECHANNEL);
148 
149  //Toggle internal reference voltage
150  //If ref generator busy, WAIT
151  while ( REF_BUSY == Ref_isRefGenBusy(REF_BASE) ) ;
152 
153  //Toggle Internal Ref between 1.5V/2.5V
154  if (vRefStatus){ //Vref == 1.5V
155  //Select internal ref = 2.5V
156  Ref_setReferenceVoltage(REF_BASE,
157  REF_VREF2_5V);
158  //vRefStatus == 0 for Vref == 2.5V
159  vRefStatus = 0;
160  } else { //Vref == 2.5V
161  //Select internal ref = 1.5V
162  Ref_setReferenceVoltage(REF_BASE,
163  REF_VREF1_5V);
164  //vRefStatus == 1 for Vref == 1.5V
165  vRefStatus = 1;
166  }
167 
168  //Conversion complete?
169  while (!(ADC10_A_getInterruptStatus(ADC10_A_BASE,
170  ADC10IFG0))) ;
171 
172  //Is ADC10MEM0 = A1 > 500
173  if (ADC10_A_getResults(ADC10_A_BASE) > 500){
174  //Set P1.0 LED on
175  GPIO_setOutputHighOnPin(GPIO_PORT_P1,
176  GPIO_PIN0
177  );
178  } else {
179  //Clear P1.0; LED off; Vref=2.5V used
180  GPIO_setOutputLowOnPin(GPIO_PORT_P1,
181  GPIO_PIN0
182  );
183  }
184 
185  //Delay between conversions
186  delay();
187  }
188 }
189 
190 void delay (void)
191 {
192  volatile uint32_t i;
193 
194  for (i = 0x7FFF; i > 0; i--){}
195 }
196 
void delay(void)
void main(void)
GPIO_setOutputHighOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
GPIO_setOutputLowOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
__delay_cycles(500000)